

class rational():
    def __init__(self, num, den=1):  # __init__ 函数创建类的对象
        self.num = num   # 第一个参数 self 表示被创建对象
        self.den = den  # 通过 self 和圆点给对象的成分赋值

    def plus(self, another):
        num = self.num * another.den + \
            self.den * another.num
        den = self.den * another.den
        return rational(num, den)

    def __add__(self, another):
        num = self.num * another.den + \
            self.den * another.num
        den = self.den * another.den

        return rational(num, den)

    def __str__(self):
        return (str(self.num) + '/' + str(self.den))


if __name__ == "__main__":
    rat1 = rational(3, 5)
    rat2 = rational(4, 6)
    rat4 = rational(3, 5)
    rat5 = rational(3.4, 6.7)
    print(rat5)

    print(rat1.num)
    print(rat1.den)
    print(rat1)

    rat1.plus(rat2)
    print(rat1)

    rat3 = rat1 + rat2
    print(rat3)
